import _ajax from '../utils/http'

// 添加评论或评论回复
function addComments (data) {
  return _ajax({
    url: '/app/v1_0/comments',
    method: 'POST',
    data,
    needToken: true
  })
}

// 举报文章
function reportArticle (data) {
  return _ajax({
    url: '/app/v1_0/article/reports',
    method: 'POST',
    data,
    needToken: true

  })
}

// 取消对文章不喜欢
function cancelArticleDislike (id) {
  return _ajax({
    url: `/app/v1_0/article/dislikes/${id}`,
    method: 'DELETE',
    needToken: true
  })
}

// 取消对文章点赞
function cancelArticleLike (id) {
  return _ajax({
    url: `/app/v1_0/article/dislikes/${id}`,
    method: 'DELETE',
    needToken: true
  })
}

// 取消对评论或评论回复点赞
function cancelCommentLike (id) {
  return _ajax({
    url: `/app/v1_0/article/dislikes/${id}`,
    method: 'DELETE',
    needToken: true
  })
}

// 取消收藏文章
function cancelArticleCollections (id) {
  return _ajax({
    url: `/app/v1_0/article/collections/${id}`,
    method: 'DELETE',
    needToken: true
  })
}

// 对文章不喜欢
function articleDislike (data) {
  return _ajax({
    url: '/app/v1_0/article/dislikes',
    method: 'POST',
    data,
    needToken: true
  })
}

// 对文章点赞
function articleLike (data) {
  return _ajax({
    url: '/app/v1_0/article/likings',
    method: 'POST',
    data,
    needToken: true
  })
}

// 对评论或评论回复点赞
function commentLike (data) {
  return _ajax({
    url: '/app/v1_0/comment/likings',
    method: 'POST',
    data,
    needToken: true
  })
}

// 收藏文章
function articleCollection (data) {
  return _ajax({
    url: '/app/v1_0/article/collections',
    method: 'POST',
    data,
    needToken: true
  })
}

// 获取新闻文章详情
function getArticleDetail (id) {
  return _ajax({
    url: `/app/v1_0/articles/${id}`,
    method: 'GET',
    needToken: true
  })
}

// 获取用户阅读历史
function getUserHistory (params) {
  return _ajax({
    url: '/app/v1_0/article/collections',
    method: 'GET',
    params,
    needToken: true
  })
}

// 获取评论或评论回复
// fixme 这里接口有疑问 query body
function getComments (params) {
  return _ajax({
    url: '/app/v1_0/comments',
    method: 'GET',
    params,
    needToken: true
  })
}

// 阅读时长埋点反馈
function readingDurations (data) {
  return _ajax({
    url: '/app/v1_0/reading/durations',
    method: 'POST',
    data,
    headers: {
      Trace: 0
    },
    needToken: true
  })
}

export {
  addComments,
  reportArticle,
  cancelArticleDislike,
  cancelArticleLike,
  cancelCommentLike,
  cancelArticleCollections,
  articleDislike,
  articleLike,
  commentLike,
  articleCollection,
  getArticleDetail,
  getUserHistory,
  getComments,
  readingDurations
}
